package com.mit.service.maintenance.dao.impl;

import java.util.List;

import com.mit.common.exception.NoRecordUpdateException;
import com.mit.common.maintenance.dto.UnitDTO;
import com.mit.service.core.dao.AbstractDAO;
import com.mit.service.maintenance.dao.IUnitDAO;

public class UnitDAOImpl extends AbstractDAO implements IUnitDAO {

	@Override
	public UnitDTO createUnit(UnitDTO unitDTO) {
		Integer id = (Integer)  getSqlMapClientTemplate().insert("insertUnit", unitDTO);
		unitDTO.setId(id);
		return unitDTO;
	}

	@Override
	public UnitDTO updateUnit(UnitDTO unitDTO)
			throws NoRecordUpdateException {
		int rs = getSqlMapClientTemplate().update("updateUnit", unitDTO);
		if(rs == 0) {
			throw new NoRecordUpdateException("No unit records!");
		}
		return unitDTO;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<UnitDTO> retrieveUnits(int organizationId) {
		return getSqlMapClientTemplate().queryForList("selectUnits", organizationId);
	}

}
